package com.cn.lp.converter.demo.converter;


import com.cn.lp.converter.MapConverter;
import com.cn.lp.converter.annotation.*;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@ConverterMapper
public interface TestMapMethodConverter extends MapConverter<TestMapMethodConverter.EntityA> {

    @Data
    class EntityA {

        private HashMap<String, Integer> emptyData;

        private int changeData;

        private int assignData;

        private long notChangeData;

        private int fromMapData;

    }

    @TypeChangeMethod(assignFromMap = true)
    default int fromMapChangeType(Object data) {
        return 10086;
    }

    @JudgeEmptyMethod
    default boolean judgeEmpty(HashMap<String, Integer> map) {
        return map == null || map.size() <= 0;
    }

    @DefaultValueMethod
    default HashMap<String, Integer> defaultValue() {
        HashMap<String, Integer> dataMap = new HashMap<>();
        dataMap.put("defaultValue", 0);
        return dataMap;
    }

    @TypeChangeMethod
    default Object changeType(int obj) {
        return "changeValue";
    }

    @TypeChangeMethod(fieldNameFilter = @FieldNameFilter(assignFieldName = "assignData"))
    default String assignChangeType(int obj) {
        return "assignValue";
    }

    @Override
    default Map<String, Object> postConvertToMap(TestMapMethodConverter.EntityA source, Map<String, Object> dataSource) {
        System.out.println("ConvertToMap 之后触发");
        return dataSource;
    }

    @Override
    default TestMapMethodConverter.EntityA preConvertFromMap(Map<String, Object> dataSource, TestMapMethodConverter.EntityA source) {
        System.out.println("ConvertFromMap 之前触发");
        return source;
    }

    @Override
    default EntityA postConvertFromMap(Map<String, Object> dataSource, EntityA source) {
        System.out.println("ConvertFromMap 之后触发");
        return source;
    }
}
